package day15.tarena.homework2;

public class Person {
	private int age;
	private String name;
	
	public Person() {
		super();
	}

	public Person(int age, String name) throws AgeException {
		super();
		this.setAge(age);
		this.setName(name);
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) throws AgeException {
		if(age>0 && age<130){
			this.age= age;
		}else{
			throw new AgeException("年龄错误");
		}
	}
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String toString(){
		return name +":" + age;
	}
	public static void main(String[] args){
		Person p = null;
		Person p2 = null;
		try{
		 p = new Person(23, "wang");
		 p2 = new Person(24,"pei");
		System.out.println(p);
		}catch(Exception ee){
			ee.printStackTrace();
		}
		System.out.println(p);
		System.out.println(p2);  
	}
	
}
